﻿DROP TRIGGER IF EXISTS  `pk_color_log`;
CREATE  TRIGGER `pk_color_log` AFTER INSERT ON `open_color`
  FOR EACH ROW BEGIN
dECLARE pkf varchar(50) DEFAULT "";
sELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="color";
if pkf <> "color" then
  INSERT INTO open_pk_log SET pk_from = 'color', pk_id = NEW.color_id;
eLSE
   update open_pk_log SET pk_id = NEW.color_id WHERE pk_from = 'color';
end if;
end;